import wx from "weixin-js-sdk";
export default {
  data() {
    return {
      baseUrl: window.location.origin+"/marketing/lottery/index.html#/",
      //  baseUrl:window.location.protocol+'//m5.yl1001.com/marketing/zhibo/index.html#/',
      architectureShare: null,  // null的时候证明不是建筑学会的直播
    };
  },
  created() {},
  computed: {

  },
  async mounted() {
    if (this.showType == 'architecture' ) {
      await this.getArchitectureShare()
    }
    this.$nextTick(() => {
      this.wxConfig();
    });
  },
  methods: {
    getArchitectureShare() {
      return this.$http({
        url: this.$http.adornUrl("/building/building/getLiveShareInfo", 'proxyHtyLocal'),
        method: "post",
        data: {
          live_id: this.liveId, 
        }
      }).then(({data}) => {
        if (data.code == 200) {
          this.architectureShare = data.data;
        }
      })
    },
    wxConfig() {
      const urlObj = {
        url: encodeURIComponent(window.location.href),
        // url: window.location.origin + '/',
      };
      this.$jsonp(
        `//m.yl1001.com/community/web/v1/index.php?m=schoolApi&a=api&func=getWechatParam&api_param=${JSON.stringify(
          urlObj
        )}`
      ).then((res) => {
        let data = this.$store.state.liveIntro;
        const config = {
          debug: false, // 开启调试模式,
          appId: res.appId, // 必填，企业号的唯一标识，此处填写企业号corpid
          timestamp: res.timestamp, // 必填，生成签名的时间戳
          nonceStr: res.nonceStr, // 必填，生成签名的随机串
          signature: res.signature, // 必填，签名，见附录1
          jsApiList: [
            "updateAppMessageShareData",
            "updateTimelineShareData",
            "onMenuShareTimeline",
            "onMenuShareAppMessage",
          ],
          success:function () {
            console.log("s updateAppMessageShareData");
            // 设置成功
          },
          fail:function () {
            console.log("f updateAppMessageShareData");
            // 设置成功
          },

          cancel:function () {
            console.log("c updateAppMessageShareData");
            // 设置成功
          },
          trigger: function () {
            console.log("updateAppMessageShareData");
            // 设置成功
          },
          complete:()=>{
            console.log('updateAppMessageShareData1');
          }
          
        };
        const linkObj = {
          title:this.luckdrawSubject.cj_title|| "校招有好礼 抽到有惊喜", // 分享标题
          desc: this.luckdrawSubject.cj_desc||'校招有好礼 抽到有惊喜',
          link: this.baseUrl + "?cj_id=" + this.cj_id, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
          imgUrl: 'https://m5.yl1001.com/marketing/spring-recruit/assets/img/banner.7672fdb1.jpg', // 分享图标
        };
        console.log('linkObj ----> ', this.cj_id);
        wx.config(config);
        wx.ready( ()=> {//success 分享回调全部回收了
          
          wx.checkJsApi({
            jsApiList: [
              "checkJsApi",
              "onMenuShareTimeline",
              "onMenuShareAppMessage",
            
            ],
            success:function () {
              console.log("s updateAppMessageShareData");
              // 设置成功
            },
            fail:function () {
              console.log("f updateAppMessageShareData");
              // 设置成功
            },

            cancel:function () {
              console.log("c updateAppMessageShareData");
              // 设置成功
            },
            trigger: function () {
              console.log("updateAppMessageShareData");
              // 设置成功
            },
            complete:()=>{
              console.log('updateAppMessageShareData1');
            }
          });
          wx.updateAppMessageShareData({
            title: linkObj.title, // 分享标题
            desc: linkObj.desc, // 分享描述
            link: linkObj.link, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
            imgUrl: linkObj.imgUrl, // 分享图标
            success:function () {
              console.log("s updateAppMessageShareData");
              // 设置成功
            },
            fail:function () {
              console.log("f updateAppMessageShareData");
              // 设置成功
            },

            cancel:function () {
              console.log("c updateAppMessageShareData");
              // 设置成功
            },
            trigger: function () {
              console.log("updateAppMessageShareData");
              // 设置成功
            },
            complete:()=>{
              console.log('updateAppMessageShareData1');
            }
          });
          wx.updateTimelineShareData({
            title: linkObj.title, // 分享标题
            desc: linkObj.desc, // 分享描述
            link: linkObj.link, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
            imgUrl: linkObj.imgUrl, // 分享图标
            success:function () {
              console.log("s updateAppMessageShareData");
              // 设置成功
            },
            fail:function () {
              console.log("f updateAppMessageShareData");
              // 设置成功
            },

            cancel:function () {
              console.log("c updateAppMessageShareData");
              // 设置成功
            },
            trigger: function () {
              console.log("updateAppMessageShareData");
              // 设置成功
            },
            complete:()=>{
              console.log('updateAppMessageShareData1');
            }
          });
          wx.onMenuShareTimeline({
            title: linkObj.title, // 分享标题
            desc: linkObj.desc, // 分享描述
            link: linkObj.link, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
            imgUrl: linkObj.imgUrl, // 分享图标
            success:function () {
              console.log("s updateAppMessageShareData");
              // 设置成功
            },
            fail:function () {
              console.log("f updateAppMessageShareData");
              // 设置成功
            },

            cancel:function () {
              console.log("c updateAppMessageShareData");
              // 设置成功
            },
            trigger: function () {
              console.log("updateAppMessageShareData");
              // 设置成功
            },
            complete:()=>{
              console.log('updateAppMessageShareData1');
            }
          });
          wx.onMenuShareAppMessage({
            title: linkObj.title, // 分享标题
            desc: linkObj.desc, // 分享描述
            link: linkObj.link, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
            imgUrl: linkObj.imgUrl, // 分享图标
            success:function () {
              console.log("s updateAppMessageShareData");
              // 设置成功
            },
            fail:function () {
              console.log("f updateAppMessageShareData");
              // 设置成功
            },

            cancel:function () {
              console.log("c updateAppMessageShareData");
              // 设置成功
            },
            trigger: function () {
              console.log("updateAppMessageShareData");
              // 设置成功
            },
            complete:()=>{
              console.log('updateAppMessageShareData1');
            }
          });
          
        });
        wx.error(function (res) {
          console.log(res);
        });
      });
    },
  },
};
